<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <div id="app1"></div>
    <script src="../js/babel.min.js"></script>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script type="text/babel">
      class Num extends React.Component {
        state = { isOne: true };
        // 自定义方法，指向一个箭头函数，箭头函数内部的this等价于外部第一个的this，也就等于该类的this，故可以直接通过this拿到state
        changeState = () => {
          this.setState({ isOne: !this.state.isOne });
        };
        render() {
          return (
            <h2 onClick={this.changeState}>
              this is {this.state.isOne ? "one" : "zero"}
            </h2>
          );
        }
      }
      ReactDOM.render(<Num />, document.getElementById("app1"));
    </script>
  </body>
</html>
